package com.gko100.dao.impl;

import java.util.List;

import com.gko100.dao.AdminPermDao;
import com.gko100.dao.basehibernatesupport.BaseHibernateDaoSupport;
import com.gko100.model.AdminPerm;
import com.gko100.model.Administrator;
import com.gko100.model.Permission;


public class AdminPermDaoHibernate extends BaseHibernateDaoSupport implements AdminPermDao {

	/* 
	 * {见接口方法说明}
	 */
	public void add_adminPerm(AdminPerm adminPerm) {
		
		this.getHibernateTemplate().save(adminPerm);
		
	}

	/* 
	 * {见接口方法说明}
	 */
	public void del_adminPerm(AdminPerm adminPerm) {
		
		this.getHibernateTemplate().delete(adminPerm);
		
	}

	/* 
	 * {见接口方法说明}
	 */
	public List<AdminPerm> findAdminPermList() {
		
		List<AdminPerm> adminPermList = this.getHibernateTemplate().find("from AdminPerm");
		if(adminPermList!=null&&adminPermList.size()>=1){
			return adminPermList;
		}else{
			logger.debug(this.getClass().getMethods().toString()+"为空");
			return null;
		}
	}
	
	/* 
	 * {见接口方法说明}
	 */
	public List<AdminPerm> findAdminPermListByAdmin(Administrator admin) {
		
		List<AdminPerm> adminPermList = this.getHibernateTemplate().find("from AdminPerm as a where a.admin=?",admin);
		if(adminPermList!=null&&adminPermList.size()>=1){
			return adminPermList;
		}else{
			logger.debug(this.getClass().getMethods().toString()+"为空");
			return null;
		}
	}
	public List<Permission> findPermListByAdmin(Administrator admin){
		
		List<Permission> permList = this.getHibernateTemplate().find("select a.perm from AdminPerm as a where a.admin=?",admin);
		if(permList!=null&&permList.size()>=1){
			return permList;
		}else{
			logger.debug(this.getClass().getMethods().toString()+"为空");
			return null;
		}
		
	}
	/* 
	 * {见接口方法说明}
	 */
	public AdminPerm findAdminPermByAdminPermId(Integer adminPermId) {
		
		AdminPerm adminPerm = this.getHibernateTemplate().get(AdminPerm.class, adminPermId);
		if(adminPerm != null){
			return adminPerm;
		}else{
			logger.debug(this.getClass().getMethods().toString()+"为空");
			return null;
		}
	}
	
	public AdminPerm findAdminPermByPerm(Permission perm){
		
		List<AdminPerm> adminPermList = this.getHibernateTemplate().find("from AdminPerm as a where a.perm=?",perm);
		if(adminPermList!=null&&adminPermList.size()>=1){
			return adminPermList.get(0);
		}else{
			logger.debug(this.getClass().getMethods().toString()+"为空");
			return null;
		}
	}
	/* 
	 * {见接口方法说明}
	 */
	public void modify_AdminPerm(AdminPerm adminPerm) {
		
		this.getHibernateTemplate().update(adminPerm);
		
	}

	/* 
	 * {见接口方法说明}
	 */
	public AdminPerm findAdminPermByAdminAndPerm(Administrator admin,
			Permission perm) {
		List<AdminPerm> adminPermList = this.getHibernateTemplate().find("from AdminPerm as a where a.admin=? and a.perm=?",admin,perm);
		if(adminPermList!=null&&adminPermList.size()>=1){
			return adminPermList.get(0);
		}else{
			logger.debug(new Exception().getStackTrace()[0].getMethodName()+"------error");
			return null;
		}
		
	}

	

}
